 	//searchcontable添加行
	 function addSearchRow() {
			var count = $("#searchcount").val(); //目前的行数
			count = parseInt(count) + 1;
			var idName = "searchInfo"+count;  //新添行的ID名
			
            var newTR = document.getElementById("searchcontable").insertRow(document.getElementById("searchcontable").rows.length);
            var newNameTD = newTR.insertCell(0);
            newNameTD.innerHTML = "<td >查询类型<select size='1'  name='"+idName+"' id='"+idName+"'  onchange='searchCue(this.id)'  >"+$("#selectValue").val()+"</select></td>";
            var newNameTD = newTR.insertCell(1);
            newNameTD.innerHTML = "<td >查询绑定字段(英)<input type='text' style='width:120px' name='"+idName+"' id='"+idName+"' /></td>";
            var newNameTD = newTR.insertCell(2);
            newNameTD.innerHTML = "<td >查询条件中文名<input type='text' style='width:120px' name='"+idName+"' id='"+idName+"' readonly  /></td>";
            var newNameTD = newTR.insertCell(3);
            newNameTD.innerHTML = "<td ><div id='searchmsg"+count+"'>更多</div><input type='text' style='width:350px'  name='"+idName+"' id='"+idName+"' readonly  /></td>";
			var newNameTD = newTR.insertCell(4);
            newNameTD.innerHTML = "<td ><input type='button'  value='删除'  onclick='delSearchCol(this)'/></td>";
			$("#searchcount").val(count);
     }
	 
		
	 //删除searchcontable行
	 function delSearchCol(obj){  
		 var index=obj.parentNode.parentNode.rowIndex;
    	 var table = document.getElementById("searchcontable");
    	 table.deleteRow(index);
	 }

	 //钻取添加行
	 function addDrillRow() {
			var count = $("#drillcount").val(); //目前的行数
			if(isNaN(count))
				count=0;
			count = parseInt(count) + 1;
			var idName = "drillInfo"+count;  //新添行的ID名
			
            var newTR = document.getElementById("drillcontable").insertRow(document.getElementById("drillcontable").rows.length);
            var newNameTD = newTR.insertCell(0);
            newNameTD.innerHTML = "<td >钻取字段(英)<input type='text' style='width:120px' name='"+idName+"' id='"+idName+"' /></td>";
            var newNameTD = newTR.insertCell(1);
            newNameTD.innerHTML = "<td >关联字段(英)<input type='text' style='width:120px' name='"+idName+"' id='"+idName+"' /></td>";
            var newNameTD = newTR.insertCell(2);
            newNameTD.innerHTML = "<td ><input type='button'  value='删除'  onclick='delDrillCol(this)'/></td>";
			$("#drillcount").val(count);
     }
	 
		
	 //删除钻取行
	 function delDrillCol(obj){  
		 var index=obj.parentNode.parentNode.rowIndex;
    	 var table = document.getElementById("drillcontable");
    	 table.deleteRow(index);
	 }
	 
	 //添加指标标签组名
	 function addTabGrp(cell){
	 	var value=$(cell).next("input").val().replace(/(^\s*)|(\s*$)/g, "");;
	 	$(cell).next("input").val('');
	 	if(value == ""){
	 		alet("请填写标签组名！");
	 		return;
	 	}
	 	if($.inArray(value, $('[name="tabGrpVal"]').val().split(';')) != -1){
	 		alert("名称重复，请重新填写！");
	 		return;
	 	}
	 	var temp='<span name="tabName" id="tabName" val="'+value+'" onDblClick="dbClick(this)">'
	 		+value
	 		+'&nbsp;&nbsp;&nbsp;<input type="button" onclick="delTabGrp(this);" value="删除"/>'
			+'&nbsp;&nbsp;&nbsp;'
			+'</span>';
		$(cell).closest('table').find('td').append(temp);
		changeTabSelect();
	 }
	 
	function delTabGrp(cell){
		$(cell).closest('span').remove();
		changeTabSelect();
	}
	
	function changeTabSelect(){
		var tabVals="";
		var tmp="";
		$('span[name="tabName"]').each(function(){
			tabVals+='<option value="'+$(this).attr('val')+'">'+$(this).attr('val')+'</option>'
			tmp+=$(this).attr('val')+';';
		});
		$('[name="tabGrpVal"]').val(tmp);
		$('table[name="colconfigtable"]').find('tr').has('td').each(function(){
			var sel=$(this).find('select[info="tabType"]');
			var value=sel.val();
			sel.html(tabVals);
			sel.find('option[value="'+value+'"]').attr('selected',true);
		});
	}
	
	//编辑后改变下拉项
	function changeTabVal(oldVal,newVal){
		var tabVals="";
		var tmp="";
		$('span[name="tabName"]').each(function(){
			tabVals+='<option value="'+$(this).attr('val')+'">'+$(this).attr('val')+'</option>'
			tmp+=$(this).attr('val')+';';
		});
		$('[name="tabGrpVal"]').val(tmp);
		$('table[name="colconfigtable"]').find('select[info="tabType"]').each(function(){
//			$(this).find('option:selected').index();
			var option=$(this).find('option[value="'+oldVal+'"]');
			option.attr('value',newVal);
			option.text(newVal);
//			option.attr('selected',true);
		});
	}
	
	//指标组双击编辑
	function dbClick(cell){
		var val = $(cell).attr('val');
		var width = $(cell).css("width");
		var height = $(cell).css("height");

		val = val.replace(/(^\s*)|(\s*$)/g, "");// trim

		$(cell).html("<input type='text' onblur='saveEdit(this,\""+val+"\")' style='width:"
				+ width + ";height:" + height
				+ "; padding:0px; margin:0px;' value='" + val + "' >");
		$(cell).children("input").focus().val(val);
	}
	
	//指标组失去焦点后保存信息
	function saveEdit(cell,oldval) {
		var span=$(cell).parent();
		var value=$(cell).val().replace(/(^\s*)|(\s*$)/g, "");
		if(value == ''){
			$(span).remove();
			changeTabSelect();
		}else{
			$(cell).remove();
			$(span).attr('val',value);
			$(span).html(value+'&nbsp;&nbsp;&nbsp;<input type="button" onclick="delTabGrp(this);" value="删除"/>&nbsp;&nbsp;&nbsp;');
			changeTabVal(oldval,value);
		}
	
	}

	 //colconfigtable添加行
	 function addColRow() {
			var count = $("#colcount").val(); //目前的行数
			count = parseInt(count) + 1;
			var idName = "colinfo"+count;  //新添行的ID名
			
            var newTR = document.getElementById("colconfigtable").insertRow(document.getElementById("colconfigtable").rows.length);
            var newNameTD = newTR.insertCell(0);
            newNameTD.innerHTML = "<td >数据库字段（英）<input type='text' style='width:160px' name='"+idName+"' id='"+idName+"' /></td>";
            var newNameTD = newTR.insertCell(1);
            newNameTD.innerHTML = "<td >字段中文名<input type='text' style='width:200px' name='"+idName+"' id='"+idName+"' /></td>";
            var newNameTD = newTR.insertCell(2);
           
            var htm = "<td>类别标签<select size='1'  info='tabType'  name='"+idName+"' id='"+idName+"' style='width:70px'>";
            $.each($('[name="tabGrpVal"]').val().split(';'), function(i,val){     
     				 if(val != ''){
     				 	htm += '<option value="'+val+'" >'+val+'</option>';
     				 }
  				});   
            htm += '</select></td>'
			 newNameTD.innerHTML =  htm;
             var newNameTD = newTR.insertCell(3);
            newNameTD.innerHTML = "<td >计算公式（不填则默认字段本身）<input type='text' style='width:200px'  name='"+idName+"' id='"+idName+"'  /></td>";
			
			
			var newNameTD = newTR.insertCell(4);
            newNameTD.innerHTML = "<td >字段类型<select size='1'  name='"+idName+"' id='"+idName+"'><option value='0' >字符</option><option value='1' >整型</option><option value='2' >浮点</option><option value='3' >百分比</option></select></td>";
			var newNameTD = newTR.insertCell(5);
            newNameTD.innerHTML = "<td >支持排序<select size='1'  name='"+idName+"' id='"+idName+"'><option value='1' >是</option><option value='0' >否</option></select></td>";
			var newNameTD = newTR.insertCell(6);
            newNameTD.innerHTML = "<td ><input type='button'  value='删除'  onclick='delColConfig(this)'/></td>";
			
			
			$("#colcount").val(count);
			
			
     }
     function trim(str){ //删除左右两端的空格
　　     return str.replace(/(^\s*)|(\s*$)/g, "");
　　 }


     function addAllColRow(){
            var textrows=$("#textforrow").val().split(",");//文本中的内容
            var firstname="";
	        var endname="";
            for(var i=0;i<textrows.length;i++)
            {
            	 var colname=textrows[i].split(" ");
	             
	             for(var j=0;j<colname.length;j++)
	             {
	             	if(""!=trim(colname[j]))
	             	{
	                    firstname=trim(colname[j]);
	                    break;
	             	}
	             }
	             for(var j=colname.length-1;j>0;j--)
	             {
	             	if(""!=trim(colname[j]))
	             	{
	                    endname=trim(colname[j]);
	                    break;
	             	}
	             }
	             console.log(firstname+"::"+endname);
	             if(firstname.indexOf("`")==-1)
	             {

	             	  firstname="";
	             }else
	             {
	             	firstname=firstname.replace("`","");
	             	firstname=firstname.replace("`","");
	             }

	             if(endname.indexOf("'")==-1)
	             {
	             	  endname="";
	             }else
	             {
	             	endname=endname.replace("'","");
	             }
	            if(firstname!=""||endname!="")
	            {
	             var count = $("#colcount").val(); //目前的行数
				count = parseInt(count) + 1;
				var idName = "colinfo"+count;  //新添行的ID名
				
	            var newTR = document.getElementById("colconfigtable").insertRow(document.getElementById("colconfigtable").rows.length);
	            var newNameTD = newTR.insertCell(0);
	            newNameTD.innerHTML = "<td >数据库字段（英）<input type='text' style='width:160px' name='"+idName+"' id='"+idName+"' value='"+firstname+"'/></td>";
	            var newNameTD = newTR.insertCell(1);
	            newNameTD.innerHTML = "<td >字段中文名<input type='text' style='width:200px' name='"+idName+"' id='"+idName+"' value='"+endname+"' /></td>";
	            var newNameTD = newTR.insertCell(2);
	           
	            var htm = "<td>类别标签<select size='1'  info='tabType'  name='"+idName+"' id='"+idName+"' style='width:70px'>";
	            $.each($('[name="tabGrpVal"]').val().split(';'), function(i,val){     
	     				 if(val != ''){
	     				 	htm += '<option value="'+val+'" >'+val+'</option>';
	     				 }
	  				});   
	            htm += '</select></td>'
				 newNameTD.innerHTML =  htm;
	             var newNameTD = newTR.insertCell(3);
	            newNameTD.innerHTML = "<td >计算公式（不填则默认字段本身）<input type='text' style='width:200px'  name='"+idName+"' id='"+idName+"' value='sum("+firstname+")'  /></td>";
				
				
				var newNameTD = newTR.insertCell(4);
	            newNameTD.innerHTML = "<td >字段类型<select size='1'  name='"+idName+"' id='"+idName+"'><option value='0' >字符</option><option value='1' selected ='selected' >整型</option><option value='2' >浮点</option><option value='3' >百分比</option></select></td>";
				var newNameTD = newTR.insertCell(5);
	            newNameTD.innerHTML = "<td >支持排序<select size='1'  name='"+idName+"' id='"+idName+"'><option value='1' >是</option><option value='0' >否</option></select></td>";
				var newNameTD = newTR.insertCell(6);
	            newNameTD.innerHTML = "<td ><input type='button'  value='删除'  onclick='delColConfig(this)'/></td>";
				
				
				$("#colcount").val(count);
	 
	            }

             }


     }
	 
		
	 //删除colconfigtable行
	 function delColConfig(obj){  
		 var index=obj.parentNode.parentNode.rowIndex;
    	 var table = document.getElementById("colconfigtable");
    	 table.deleteRow(index);
	 }
	 
	 
	 //删除表格所有行
	 function delTableAllRow(tableName){  
    	 var tb = document.getElementById(tableName);
		 var rowNum= tb.rows.length;
         for (i=1;i<=rowNum;i++)
         {
             tb.deleteRow(i);
             rowNum=rowNum-1;
             i=i-1;
         }
     }
	 
	 
		 $(function(){$("#update").click(function(){
            	jQuery.ajax({
        			url:"/intreport/updatereport",
            		type:"post",
            		async:true,
					data : $('#updatereportform').serialize(), 
            		success:function(result){
						if(result == "success"){
							alert("更新成功，请刷新页面。");
						}else{
							alert(result);
						}
            		}
            	});
        	 })
         })
	 
         
		$(function(){$("#addnew").click(function(){
            	jQuery.ajax({
        			url:"/intreport/addnewreport",
            		type:"post",
            		async:true,
					data : $('#addnewreportform').serialize(), 
            		success:function(result){
						if(result == "success"){
							alert("添加成功，请刷新页面。");
						}else{
							alert(result);
						}
            		}
            	});
        	 })
         })
         
         function searchCue(id){
			var inputList = document.getElementsByName(id);
			var count = id.substring(id.length-1,id.length);
			var msgName = "searchmsg"+ count;	
			var span = document.getElementById(msgName);
			
			//初始化
			span.innerHTML = "更多"
			setCanInput(inputList[1]);
			setCanInput(inputList[2]);
			setCanInput(inputList[3]);
			
			var typeId = inputList[0].value;//查询类型编号
			if(typeId == 1){
				setNoInput(inputList[2]);
				setNoInput(inputList[3]);
			}else if(typeId == 3){
				setNoInput(inputList[2]);
				setNoInput(inputList[3]);
			}else if(typeId == 4){
				setNoInput(inputList[2]);
				setNoInput(inputList[3]);
			}else if(typeId == 5){
				setNoInput(inputList[3]);
			}else if(typeId == 6){
				setNoInput(inputList[3]);
			}else if(typeId == 7){
				span.innerHTML = "更多 &nbsp<span style='color:red'>(数据库值:展示名。可多个，每组之间以分号隔开。)</span>"
			}else if(typeId == 8){
				setNoInput(inputList[1]);
				setNoInput(inputList[2]);
				span.innerHTML = "更多 &nbsp<span style='color:red'>(数据库字段名:展示名。可多个，每组之间以分号隔开。)</span>"
			}else if(typeId == 9){
				setNoInput(inputList[2]);
				span.innerHTML = "更多 &nbsp<span style='color:red'>(级联层数：1-3，注意与查询绑定字段数保持一致 。)</span>"
			}else if(typeId == 10){
				setNoInput(inputList[2]);
				span.innerHTML = "更多 &nbsp<span style='color:red'>(级联层数：1-3，注意与查询绑定字段数保持一致 。)</span>"
			}else if(typeId == 11){
				setNoInput(inputList[2]);
				span.innerHTML = "更多 &nbsp<span style='color:red'>(级联层数：1-3，注意与查询绑定字段数保持一致 。)</span>"
			}else if(typeId == 12){
				setNoInput(inputList[2]);
				span.innerHTML = "更多 &nbsp<span style='color:red'>(级联层数：1-3，注意与查询绑定字段数保持一致 。)</span>"
			}else if(typeId == 13){
				setNoInput(inputList[1]);
				setNoInput(inputList[2]);
				span.innerHTML = "更多 &nbsp<span style='color:red'>(1：曲线图，2：饼图。K:V形式，每组以分号隔开。)</span>"
			}else if(typeId == 14){
				setNoInput(inputList[2]);
				span.innerHTML = span.innerHTML = "<span style='color:red'>("+$("#dpValues").val()+")</span>"
			}else if(typeId == 15){
				setNoInput(inputList[1]);
				setNoInput(inputList[2]);
				setNoInput(inputList[3]);
			}else if(typeId == 16){
				setNoInput(inputList[1]);
				setNoInput(inputList[2]);
				setNoInput(inputList[3]);
			}
		}
		
		
		//对象置灰 + 只读 
		function setNoInput(input){
			input.value = "";
			input.readOnly = true;
			input.style.backgroundColor ="#888888";
		}
		
		//对象可填
		function setCanInput(input){
			input.value = "";
			input.readOnly = false;
			input.style.backgroundColor ="#FFFFFF";
		}
	